/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Controller;

import Model.Intersection;
import Model.Menu;
import Model.Traffic_Lights;
import java.util.ArrayList;

/**
 * Class that coordinates all the other classes in the simulation.
 * @author Luke
 */
public class Coordinator {

    /**
     * The main sole method in the Coordinator method. The main method controls all the other classes.
     * @param args Not utilised.
     */
    public static void main(String[] args) {
        Menu menu = new Menu(); //Make instance of menu
        ArrayList streetValues = menu.runMenu(); //Run the menu save the output to an ArrayList
        Intersection intersection = new Intersection(streetValues); //Make and instance of the intersection class
        intersection.generate_Lanes(10); //make a intersection grid with filler of 10 spaces
        boolean running = true; //Boolean for controller loop
        Traffic_Lights lightControl = new Traffic_Lights(intersection.getNumVStreet()); //Instance fo tthe class that controlls traffic

        while (running) {

            ArrayList newVCars = intersection.makeCars("vertical"); //make the vertical cars
            if (newVCars != null) {
                intersection.getVertArray().set(0, newVCars); //add the freshley generated cars to the vert array
            }

            ArrayList newHCars = intersection.makeCars("horizontal"); //make horizontal cars
            if (newHCars != null) {
                for (int i = 0; i < intersection.getHorzArray().size(); i++) {
                    intersection.getHorzArray().get(i).set(0, newHCars.get(i)); //set cuurent nested array first element to current newCar
                }
            }
            intersection.drawIntersection(); //Draw the intersection
            intersection.moveHCars(lightControl.getH_Lights()); //Move the horizontal cars
            intersection.moveVCars(lightControl.getV_Lights()); //Move the vertical cars
            lightControl.incrementCount(); //INcrement the counter for light cycle for the traffic lights
            System.out.println("VStreet-Lights: " + lightControl.getV_Lights()); //Display traffic status at vertical lights
            System.out.println("HStreet-Lights: " + lightControl.getH_Lights()); //Display traffic status at horizontal lights

        }
    }
}
